package cn.itcast;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
@WebServlet("/liststudent")
public class ListStudent extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader br = new BufferedReader(new FileReader("D:\\stu.txt"));
        ArrayList<Student> arr = new ArrayList<>();
        String str;
        while ((str = br.readLine()) != null) {
            String[] s = str.split(",");
            Student student = new Student(s[0], Integer.parseInt(s[1]), Integer.parseInt(s[2]));
            arr.add(student);
        }
        req.getSession().setAttribute("arr",arr);
        resp.sendRedirect("/stu4.6/liststudent.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
